import request from '@/service/lib/request';
import hiSetting from '@/hiSetting'
/**
 * 用户 - 登录
 * @param {String} url 请求地址
 * @param {Object} data 请求参数
 * @author LiQingSong
 */
export function login(url, data) {
  return request({
    url: url,
    method: 'post',
    data
  });
}

/**
 * 用户 - 获取用户信息和权限
 * @author LiQingSong
 */
export function getLoginState() {
  return request({
    // url: '/user/info',
    url: hiSetting.server + "/pub/userinfo",
    method: 'get',
  });
}
// 获取基础信息
export function getInfo() {
  return request({
    // url: '/user/info',
    url: hiSetting.server + "/userPersonalApi/get",
    method: 'get',
    // params: { token: token }
  });
}
/**
 * 用户 - 退出
 * @author LiQingSong
 */
export function logout(url) {
  return request({
    url: url,
    method: 'post'
  });
}


// 修改密码
export function modifyPwd(data) {
  return request({
    url: hiSetting.server + "/userPersonalApi/modifyPwd",
    method: 'post',
    data,
    transformRequest: [
      function (data) {
        let ret = ''
        for (let it in data) {
          ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
        }
        ret = ret.substring(0, ret.lastIndexOf('&'));
        return ret
      }
    ],
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  });
}
// 修改基础信息
export function modifyInfo(data) {
  return request({
    url: hiSetting.server + "/userPersonalApi/add",
    method: 'post',
    data,
    transformRequest: [
      function (data) {
        let ret = ''
        for (let it in data) {
          ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
        }
        ret = ret.substring(0, ret.lastIndexOf('&'));
        return ret
      }
    ],
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  });
}

//用户信息
export function getUser() {
  return request({
    url: hiSetting.server + "/userApi/get",
    method: 'get',
    // params: { token: token }
  });
}

//修改手机号
export function modifyPhone(data) {
  return request({
    url: hiSetting.server + "/userApi/modifyMobile",
    method: 'post',
    data,
    transformRequest: [
      function (data) {
        let ret = ''
        for (let it in data) {
          ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
        }
        ret = ret.substring(0, ret.lastIndexOf('&'));
        return ret
      }
    ],
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  });
}
//修改邮箱
export function modifyEmail(data) {
  return request({
    url: hiSetting.server + "/userApi/modifyEmail",
    method: 'post',
    data,
    transformRequest: [
      function (data) {
        let ret = ''
        for (let it in data) {
          ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
        }
        ret = ret.substring(0, ret.lastIndexOf('&'));
        return ret
      }
    ],
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  });
}

